﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using soho.Library;

public partial class CRMUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!Page.IsPostBack)
        {
            if (Session[GeneralUsage.CurrentUser] != null)
            {
                Customer customer = (Customer)Session[GeneralUsage.CurrentUser];
                txtUserName.Text = customer.UserName;
                txtFullName.Text = customer.FullName;
                txtCompanyName.Text = customer.CompanyName;
                txtEmail.Text = customer.Email;
                txtPhoneNumber.Text = customer.PhoneNumber;
                txtAddress.Text = customer.Address;
                txtPassword.Text = customer.Password;
            }
            lblError.Text = "";
        }
    }
    protected void btnSignUp_Click(object sender, EventArgs e)
    {
        //Update
        
        Customer    customer = new Customer();
        customer.UserName = txtUserName.Text;
        customer.Password = txtPassword.Text;
        customer.FullName = txtFullName.Text.Trim();
        customer.CompanyName = txtCompanyName.Text.Trim();
        customer.Address = txtAddress.Text.Trim();
        customer.PhoneNumber = txtPhoneNumber.Text.Trim();
        customer.Email = txtEmail.Text.Trim();

        try
        {
            CustomerUtl.Update(customer);
        }
        catch (Exception ex)
        {
            lblError.Text = GetLocalResourceObject("lblError.Text.Error").ToString();

            return;
        }

        lblError.Text = GetLocalResourceObject("lblError.Text.Success").ToString();
        customer = CustomerUtl.GetCustomer(txtUserName.Text);
        Session[GeneralUsage.CurrentUser] = customer;
        
        txtUserName.Text = customer.UserName;
        txtFullName.Text = customer.FullName;
        txtCompanyName.Text = customer.CompanyName;
        txtEmail.Text = customer.Email;
        txtPhoneNumber.Text = customer.PhoneNumber;
        txtAddress.Text = customer.Address;
        txtPassword.Text = customer.Password;

    }
}